/*
 * Copyright (C) 2011 Jesus Navalon i Pastor <jnavalon at redhermes dot net>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/*
 * pn_deploy.java
 *
 * Created on 10/09/2011, 20:02:20
 */
package kuasar.plugin.deployer.gui;

import java.util.ArrayList;
import javax.swing.JPanel;
import kuasar.plugin.Intercom.GUI;
import kuasar.plugin.deployer.gui.actions.dialogs.pn_AllocateErr;
import kuasar.plugin.deployer.gui.actions.th_Deploy;
import kuasar.plugin.deployer.gui.classmod.I_Panels;
import org.jdom.Element;

/**
 *
 * @author Jesus Navalon i Pastor <jnavalon at redhermes dot net>
 */
public class pn_Deploy extends kuasar.plugin.classMod.AbstractPanel implements I_Panels {

    private JPanel first;
    private Element vms;
    private th_Deploy deploy;
    /** Creates new form pn_deploy */
    public pn_Deploy(JPanel first, Element vms) {
        this.first = first;
        this.vms = vms;
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        pn_Title = new javax.swing.JPanel();
        lbl_Title = new javax.swing.JLabel();
        pn_Buttons = new javax.swing.JPanel();
        btn_Stop = new javax.swing.JButton();
        pn_Center = new javax.swing.JPanel();
        pn_Left = new javax.swing.JPanel();
        pn_Right = new javax.swing.JPanel();
        pn_Upper = new javax.swing.JPanel();
        pn_Lower = new javax.swing.JPanel();
        lbl_Info = new kuasar.plugin.deployer.gui.classmod.JMarqueeLabel();
        lbl_Current = new kuasar.plugin.deployer.gui.classmod.JMarqueeLabel();

        setOpaque(false);

        pn_Title.setOpaque(false);

        lbl_Title.setFont(new java.awt.Font("Dialog", 1, 24)); // NOI18N
        lbl_Title.setForeground(new java.awt.Color(204, 204, 204));
        lbl_Title.setIcon(new javax.swing.ImageIcon(getClass().getResource("/kuasar/plugin/deployer/icons/start.png"))); // NOI18N
        lbl_Title.setText("Deploying");

        javax.swing.GroupLayout pn_TitleLayout = new javax.swing.GroupLayout(pn_Title);
        pn_Title.setLayout(pn_TitleLayout);
        pn_TitleLayout.setHorizontalGroup(
            pn_TitleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pn_TitleLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(lbl_Title, javax.swing.GroupLayout.PREFERRED_SIZE, 571, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        pn_TitleLayout.setVerticalGroup(
            pn_TitleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pn_TitleLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(lbl_Title)
                .addContainerGap())
        );

        pn_Buttons.setOpaque(false);

        btn_Stop.setBackground(new java.awt.Color(0, 0, 0));
        btn_Stop.setForeground(new java.awt.Color(204, 204, 204));
        btn_Stop.setIcon(new javax.swing.ImageIcon(getClass().getResource("/kuasar/plugin/deployer/icons/abort22.png"))); // NOI18N
        btn_Stop.setText("Abort");
        btn_Stop.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_StopActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout pn_ButtonsLayout = new javax.swing.GroupLayout(pn_Buttons);
        pn_Buttons.setLayout(pn_ButtonsLayout);
        pn_ButtonsLayout.setHorizontalGroup(
            pn_ButtonsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pn_ButtonsLayout.createSequentialGroup()
                .addContainerGap(488, Short.MAX_VALUE)
                .addComponent(btn_Stop)
                .addContainerGap())
        );
        pn_ButtonsLayout.setVerticalGroup(
            pn_ButtonsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pn_ButtonsLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(btn_Stop, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        pn_Center.setOpaque(false);

        javax.swing.GroupLayout pn_CenterLayout = new javax.swing.GroupLayout(pn_Center);
        pn_Center.setLayout(pn_CenterLayout);
        pn_CenterLayout.setHorizontalGroup(
            pn_CenterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 509, Short.MAX_VALUE)
        );
        pn_CenterLayout.setVerticalGroup(
            pn_CenterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 217, Short.MAX_VALUE)
        );

        pn_Left.setOpaque(false);

        javax.swing.GroupLayout pn_LeftLayout = new javax.swing.GroupLayout(pn_Left);
        pn_Left.setLayout(pn_LeftLayout);
        pn_LeftLayout.setHorizontalGroup(
            pn_LeftLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 37, Short.MAX_VALUE)
        );
        pn_LeftLayout.setVerticalGroup(
            pn_LeftLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 306, Short.MAX_VALUE)
        );

        pn_Right.setOpaque(false);

        javax.swing.GroupLayout pn_RightLayout = new javax.swing.GroupLayout(pn_Right);
        pn_Right.setLayout(pn_RightLayout);
        pn_RightLayout.setHorizontalGroup(
            pn_RightLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 37, Short.MAX_VALUE)
        );
        pn_RightLayout.setVerticalGroup(
            pn_RightLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 306, Short.MAX_VALUE)
        );

        pn_Upper.setOpaque(false);

        javax.swing.GroupLayout pn_UpperLayout = new javax.swing.GroupLayout(pn_Upper);
        pn_Upper.setLayout(pn_UpperLayout);
        pn_UpperLayout.setHorizontalGroup(
            pn_UpperLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 509, Short.MAX_VALUE)
        );
        pn_UpperLayout.setVerticalGroup(
            pn_UpperLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 39, Short.MAX_VALUE)
        );

        pn_Lower.setOpaque(false);

        lbl_Info.setForeground(new java.awt.Color(204, 204, 204));

        lbl_Current.setForeground(new java.awt.Color(204, 204, 204));
        lbl_Current.setText("a");

        javax.swing.GroupLayout pn_LowerLayout = new javax.swing.GroupLayout(pn_Lower);
        pn_Lower.setLayout(pn_LowerLayout);
        pn_LowerLayout.setHorizontalGroup(
            pn_LowerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(lbl_Info, javax.swing.GroupLayout.DEFAULT_SIZE, 509, Short.MAX_VALUE)
            .addComponent(lbl_Current, javax.swing.GroupLayout.DEFAULT_SIZE, 509, Short.MAX_VALUE)
        );
        pn_LowerLayout.setVerticalGroup(
            pn_LowerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pn_LowerLayout.createSequentialGroup()
                .addComponent(lbl_Current, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 10, Short.MAX_VALUE)
                .addComponent(lbl_Info, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(pn_Buttons, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addComponent(pn_Left, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(pn_Lower, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(pn_Center, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(pn_Upper, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(pn_Right, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addComponent(pn_Title, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(pn_Title, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(pn_Right, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(pn_Left, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(pn_Upper, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(pn_Center, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(pn_Lower, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(pn_Buttons, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void btn_StopActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_StopActionPerformed
        if(deploy!=null){
            deploy.stopclean();
        }
    }//GEN-LAST:event_btn_StopActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btn_Stop;
    private javax.swing.JLabel lbl_Current;
    private javax.swing.JLabel lbl_Info;
    private javax.swing.JLabel lbl_Title;
    private javax.swing.JPanel pn_Buttons;
    private javax.swing.JPanel pn_Center;
    private javax.swing.JPanel pn_Left;
    private javax.swing.JPanel pn_Lower;
    private javax.swing.JPanel pn_Right;
    private javax.swing.JPanel pn_Title;
    private javax.swing.JPanel pn_Upper;
    // End of variables declaration//GEN-END:variables

    public void start(){
        deploy = new th_Deploy(vms, this);
        deploy.start();
    }
    @Override
    public void goNext() {
        GUI.loadPlugin(new pn_AllOK(first));
        GUI.updateUI();
    }

    @Override
    public void goPrevious() {
        throw new UnsupportedOperationException("Not supported yet.");
    }
    public void changePanel(JPanel panel){
        pn_Center.removeAll();
        pn_Center.add(panel);
        panel.setBounds(0,0,pn_Center.getWidth(), pn_Center.getHeight());
        panel.setVisible(true);
        pn_Center.updateUI();
    }
    public void setInfo(String msg){
        lbl_Info.setText(msg);
    }
    public void setCurrentMachime(String machine){
        lbl_Current.setText(machine);
    }

    public void showErrors(ArrayList<String[]> errors) {
        GUI.loadPlugin(new pn_AllocateErr(errors,first));
        GUI.updateUI();
    }
    
    
}
